<?php


namespace app\common\command;


use app\admin\model\Duty;
use app\http\Http;
use app\sys\model\Dict;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\facade\Env;

class UserDuty extends Command
{
    protected function configure()
    {
        $this->setName('user_duty')
            ->setDescription('用户职位拉取');
    }

    protected function execute(Input $input, Output $output)
    {
        $host = Env::get("USER_SYS.USER_SYS_API");
        $dy = Env::get("USER_SYS.USER_DUTY");
        $accessKeyId =  Env::get("USER_SYS.USER_SYS_ACCKEYID");
        $signature =  Env::get("USER_SYS.USER_SYS_SIGN");
        $url = $host.$dy;
        $data = Http::doPost($url,["AccessKeyId"=>$accessKeyId,"Signature"=>$signature]);
        $res = json_decode($data,true);
        if ($res["code"] != 200) $output->writeln("gw_site code false");
        Db::startTrans();
        try {
            Duty::coverDutyAdd($res["data"]);
            Db::commit();
            $output->writeln("user_duty success");
        } catch (\Exception $e) {
            $output->writeln("user_duty false");
            Db::rollback();
        }
    }
}